﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Synthesis;

namespace simWaifu
{
    static class SpeechHandler
    {
        static public SpeechSynthesizer speak = null;

        static public SpeechSynthesizer Initialize()
        {
            return SpeechHandler.Initialize(0);
        }
        
        static public SpeechSynthesizer Initialize(int rate)
        {
            speak = new SpeechSynthesizer();

            if (speak != null)
            {
                speak.Rate = rate;  //The Voice Speed
                foreach (InstalledVoice voice in speak.GetInstalledVoices())
                {
                    string s = (voice.VoiceInfo.Description);
                    string s1 = voice.VoiceInfo.Name;
                    DebugMessageHandler.WriteMsgLine("Voice installed: " + s1);                    
                }
                speak.SpeakAsync("Speech initialized.");
            }

            return speak;
        }

        static public void ShutDown()
        {
            speak = null;
        }

        static public void Say(string s)
		{
            if (speak != null)
            {
                //Speak.Speak(DateTime.Now.ToString());
                speak.SpeakAsync(s);
            }
		}

        static public void SelectVoice()
        {
            if (speak != null)
            {
                FormSelectVoice frmSelectVoice = new FormSelectVoice();
                frmSelectVoice.ShowDialog();
            }
        }

        static public void SetVoice(string v)
        {
            try
            {
                if (speak != null)
                {
                    speak.SelectVoice(v);
                }
            }
            catch (Exception e)
            {
                DebugMessageHandler.WriteErrorLine("Could not change to voice " + v);
                DebugMessageHandler.WriteErrorLine(e.Message);
            }
        }
    }
}
